import { ResultCode, ResultCodeMessages } from '../enums/resultCode';

class Result {
  code: number | string;
  data: any;
  desc: string;
  success: boolean;

  constructor(code: number | string, data: any, desc: string, success?: boolean) {
    this.code = code;
    this.desc = desc;
    this.data = data;
    this.success = success;
  }

  static response(result: Result) {
    return new Result(result.code, result.data, result.desc, result.success);
  }

  static success(data?: any, message?: string) {
    return new Result(ResultCode.SUCCESS, data ? data : '', message || ResultCodeMessages[ResultCode.SUCCESS], true);
  }

  static fail(code: ResultCode, desc: string) {
    return new Result(code, null, desc, false);
  }

  static customer(code: ResultCode, data?: any, desc?: string, success?: boolean) {
    return new Result(code, data, desc, success);
  }

}

export default Result;